<template>
    <el-dialog
            :title="!dataForm.id ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
                            <el-form-item label="主键ID" prop="id">
                        <el-input v-model.number="dataForm.id" placeholder="主键ID"></el-input>
                </el-form-item>
                <el-form-item label="客户ID" prop="customerId">
                        <el-input v-model.number="dataForm.customerId" placeholder="客户ID"></el-input>
                </el-form-item>
                <el-form-item label="客户年龄" prop="age">
                        <el-input v-model.number="dataForm.age" placeholder="客户年龄"></el-input>
                </el-form-item>
                <el-form-item label="客户职业" prop="occupation">
                        <el-input v-model="dataForm.occupation" placeholder="客户职业"></el-input>
                </el-form-item>
                <el-form-item label="客户收入" prop="income">
                        <el-input v-model="dataForm.income" placeholder="客户收入"></el-input>
                </el-form-item>
                <el-form-item label="逾期记录次数" prop="overdueRecords">
                        <el-input v-model.number="dataForm.overdueRecords" placeholder="逾期记录次数"></el-input>
                </el-form-item>
                <el-form-item label="违约次数" prop="breachCount">
                        <el-input v-model.number="dataForm.breachCount" placeholder="违约次数"></el-input>
                </el-form-item>
                <el-form-item label="资产总值" prop="assetValue">
                        <el-input v-model="dataForm.assetValue" placeholder="资产总值"></el-input>
                </el-form-item>
                <el-form-item label="负债总值" prop="liabilityValue">
                        <el-input v-model="dataForm.liabilityValue" placeholder="负债总值"></el-input>
                </el-form-item>
                <el-form-item label="信用风险评分" prop="creditRiskScore">
                        <el-input v-model="dataForm.creditRiskScore" placeholder="信用风险评分"></el-input>
                </el-form-item>
                <el-form-item label="潜在欺诈风险标志（TRUE为高风险）" prop="fraudRiskFlag">
                        <el-input v-model="dataForm.fraudRiskFlag" placeholder="潜在欺诈风险标志（TRUE为高风险）"></el-input>
                </el-form-item>
                <el-form-item label="创建时间" prop="createdAt">
                        <el-date-picker
                                v-model="dataForm.createdAt"
                                type="datetime"
                                placeholder="创建时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="更新时间" prop="updatedAt">
                        <el-date-picker
                                v-model="dataForm.updatedAt"
                                type="datetime"
                                placeholder="更新时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="交易行为模式描述" prop="transactionBehavior">
                        <el-input v-model="dataForm.transactionBehavior" placeholder="交易行为模式描述"></el-input>
                </el-form-item>
                <el-form-item label="外部信用数据" prop="externalCreditData">
                        <el-input v-model="dataForm.externalCreditData" placeholder="外部信用数据"></el-input>
                </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
    export default {
      data () {
        return {
          visible: false,
          dataForm: {
            id: null,
            customerId: null,
            age: null,
            occupation: null,
            income: null,
            overdueRecords: null,
            breachCount: null,
            assetValue: null,
            liabilityValue: null,
            creditRiskScore: null,
            fraudRiskFlag: null,
            createdAt: null,
            updatedAt: null,
            transactionBehavior: null,
            externalCreditData: null
          },
          dataRule: {
            id: [
                        { required: true, message: '主键ID不能为空', trigger: 'blur' }
            ],
            customerId: [
                        { required: true, message: '客户ID不能为空', trigger: 'blur' }
            ],
            age: [
                        { required: true, message: '客户年龄不能为空', trigger: 'blur' }
            ],
            occupation: [
                        { required: true, message: '客户职业不能为空', trigger: 'blur' }
            ],
            income: [
                        { required: true, message: '客户收入不能为空', trigger: 'blur' }
            ],
            overdueRecords: [
                        { required: true, message: '逾期记录次数不能为空', trigger: 'blur' }
            ],
            breachCount: [
                        { required: true, message: '违约次数不能为空', trigger: 'blur' }
            ],
            assetValue: [
                        { required: true, message: '资产总值不能为空', trigger: 'blur' }
            ],
            liabilityValue: [
                        { required: true, message: '负债总值不能为空', trigger: 'blur' }
            ],
            creditRiskScore: [
                        { required: true, message: '信用风险评分不能为空', trigger: 'blur' }
            ],
            fraudRiskFlag: [
                        { required: true, message: '潜在欺诈风险标志（TRUE为高风险）不能为空', trigger: 'blur' }
            ],
            createdAt: [
                        { required: true, message: '创建时间不能为空', trigger: 'blur' }
            ],
            updatedAt: [
                        { required: true, message: '更新时间不能为空', trigger: 'blur' }
            ],
            transactionBehavior: [
                        { required: true, message: '交易行为模式描述不能为空', trigger: 'blur' }
            ],
            externalCreditData: [
                        { required: true, message: '外部信用数据不能为空', trigger: 'blur' }
            ]
          }
        }
      },
      methods: {
        init (id) {
          this.dataForm.id = id || 0
          this.visible = true
          this.$nextTick(() => {
            this.$refs['dataForm'].resetFields()
            this.dataForm.id = id || 0
            if (this.dataForm.id) {
              this.$http({
                url: this.$http.adornUrl(`/app/credit_risk/info/${this.dataForm.id}`),
                method: 'get',
                params: this.$http.adornParams()
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.dataForm = data.appcreditrisk
                }
              })
            }
          })
        },
            // 表单提交
        dataFormSubmit () {
          this.$refs['dataForm'].validate((valid) => {
            if (valid) {
              this.$http({
                url: this.$http.adornUrl(`/app/credit_risk/${!this.dataForm.id ? 'save' : 'update'}`),
                method: 'post',
                data: this.$http.adornData(this.dataForm)
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
                      this.visible = false
                      this.$emit('refreshDataList')
                    }
                  })
                } else {
                  this.$message.error(data.msg)
                }
              })
            }
          })
        }
      }
    }
</script>